/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import etcore.webapp.grouptalk.common.dao.BaseDAO;
import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.dao.MessageDAO;
import etcore.webapp.grouptalk.common.object.Comment;
import etcore.webapp.grouptalk.common.object.Message;

/**
 * MessageService implements queries and transactions on Message
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class MessageService extends BaseService {

	public int batchTopicTransforming(Integer sourceTopicId,
			Integer targetTopicId) {
		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		try {
			MessageDAO dao = new MessageDAO();
			int result = dao.batchTopicTransforming(sourceTopicId,
					targetTopicId);
			tx.commit();
			return result;

		} catch (RuntimeException re) {

			tx.rollback();
			return -1;
		} finally {
			if (session != null)
				session.close();
		}
	}

	@SuppressWarnings("rawtypes")
	@Override
	public void deleteList(List persistentInstanceList) {

		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		try {
			BaseDAO dao = new MessageDAO();
			dao.deleteList(persistentInstanceList);
			tx.commit();

		} catch (RuntimeException re) {

			tx.rollback();
		} finally {
			if (session != null)
				session.close();
		}

	}

	@Override
	public void deleteSingle(Object persistentInstance) {

		Session session = HibernateSessionFactory.getSession();
		Transaction tx = session.beginTransaction();
		try {
			BaseDAO dao = new MessageDAO();
			dao.deleteSingle(persistentInstance);
			tx.commit();

		} catch (RuntimeException re) {
re.printStackTrace();
			tx.rollback();
		} finally {
			if (session != null)
				session.close();
		}
	}

	@SuppressWarnings("rawtypes")
	public List findActiveUsers(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findActiveUsers(begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<Message> findAll(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List<Message> result = dao.findAll(begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public Message findById(java.lang.Integer id) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			Message result = dao.findById(id);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findByProperty(String propertyName, Object value, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findByProperty(propertyName, value, begin,
					length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findIDsByPropertyAndFlag(String propertyName, Object value, Integer flag,int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findIDsByPropertyAndFlag(propertyName, value, flag,begin,
					length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findAllByProperty(String propertyName, Object value, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findAllByProperty(propertyName, value, begin,
					length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findByPropertyAndTags(String propertyName, Object value,
			List<String> tagList, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findByPropertyAndTags(propertyName, value,
					tagList, begin, length);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

 

	public long findCommentNum(Integer gmid) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findCommentNum(gmid);

			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeOfEvents(boolean local,String startDate, String endDate) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfEvents(local,startDate, endDate);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeOfEvents(String startDate, String endDate,Integer directoryID) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfEvents(startDate, endDate,directoryID);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeOfEvents(String startDate, String endDate,String userName) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfEvents(startDate, endDate,userName);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	
	public long findSizeOfFavouriteEvents(String startDate, String endDate,String userName) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfFavouriteEvents(startDate, endDate,userName);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findEvents(boolean local,String startDate, String endDate, int begin,
			int length, String rankField, boolean desc) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findEvents(local,startDate, endDate, begin, length,
					rankField, desc);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findEvents(String startDate, String endDate,Integer directoryID, int begin,
			int length, String rankField, boolean desc) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findEvents(startDate, endDate, directoryID,begin, length,
					rankField, desc);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findEvents(String startDate, String endDate, String userName,
			int begin, int length, String rankField, boolean desc) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findEvents(startDate, endDate, userName, begin,
					length, rankField, desc);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findFavouriteEvents(String startDate, String endDate,
			String userName, int begin, int length, String rankField,
			boolean desc) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findFavouriteEvents(startDate, endDate, userName,
					begin, length, rankField, desc);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findFavouriteMessages(String userName, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findFavouriteMessages(userName, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findFavouriteMessages(String userName, Integer open, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findFavouriteMessages(userName, open, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findFullRecordByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findFullRecordByProperty(propertyName, value);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findHottestPublicEnglishMessages(int days, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findHottestPublicEnglishMessages(days, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findHottestEnglishMessagesByOpen(int open, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findHottestEnglishMessagesByOpen(open, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findHottestLocalMessagesByOpen(int open, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findHottestLocalMessagesByOpen(open, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findHottestPublicLocalMessages(int days, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findHottestPublicLocalMessages(days, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findHottestPublicMessages(int days, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findHottestPublicMessages(days, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public Comment findLastComment(Integer gmid) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			Comment result = dao.findLastComment(gmid);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findMessages(String propertyName, Object value, Integer open,
			int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findMessages(propertyName, value, open, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findMessages(String propertyName, Object value, Integer open,
			Integer nav, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findMessages(propertyName, value, open, nav,
					begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findMsgsByGid(Integer g, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findMsgsByGid(g, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findByGidOrderByClick(Integer g, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findByGidOrderByClick(g, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findMsgsByGidAndTags(Integer g, List<String> tagList,
			int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findMsgsByGidAndTags(g, tagList, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findPublicEnglishMessages(int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findPublicEnglishMessages(begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findPublicLocalMessages(int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findPublicLocalMessages(begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findPublicMessages(int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findPublicMessages(begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findPublicMessagesByInterval(String startDate,String endDate,int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findPublicMessagesByInterval(startDate, endDate, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	@SuppressWarnings("rawtypes")
	public List findPublicMessages(String propertyName, Object value,
			int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findPublicMessages(propertyName, value, begin,
					length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findRecentActiveUsers(int days, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findRecentActiveUsers(days, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}
	}
	@SuppressWarnings("rawtypes")
	public List findByFutureDaysAndTid(String inputDate,Integer days, Integer tid,int begin, int length){
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findByFutureDaysAndTid(inputDate, days,tid,begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}
	}

	@SuppressWarnings("rawtypes")
	public List findSegments(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findSegments(begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findSharedFiles(Integer g, Integer flag, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findSharedFiles(g, flag, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findSharedFiles(String userName, Integer flag, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findSharedFiles(userName, flag, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findSharedFiles(String userName, Integer g, Integer flag,
			int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findSharedFiles(userName, g, flag, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeByFutureDaysAndTid(Integer days, Integer tid) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByFutureDaysAndTid(days, tid);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeByFutureDaysAndTid(String inputDate,Integer days, Integer tid) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByFutureDaysAndTid(inputDate,days, tid);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeOfPublicMessagesByInterval(String startDate,String endDate) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfPublicMessagesByInterval(startDate, endDate);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeByDaysAndGid(Integer days, Integer g) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByDaysAndGid(days, g);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByGid(Integer g) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByGid(g);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
 
	public long findSizeByGidAndTags(Integer g, List<String> tagList) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByGidAndTags(g, tagList);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findAllSizeByProperty(String propertyName, Object value) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findAllSizeByProperty(propertyName, value);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeByProperty(String propertyName, Object value) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByProperty(propertyName, value);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByPropertyAndTags(String propertyName, Object value,
			List<String> tagList) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByPropertyAndTags(propertyName, value,
					tagList);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSizeByPropertyAndFlag(String propertyName, Object value,
			Integer flag) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeByPropertyAndFlag(propertyName, value,
					flag);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfFavouriteMessages(String userName) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfFavouriteMessages(userName);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfFavouriteMessages(String userName, Integer open) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfFavouriteMessages(userName, open);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfMessages(String propertyName, Object value,
			Integer open) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfMessages(propertyName, value, open);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfMessages(String propertyName, Object value,
			Integer open, Integer nav) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao
					.findSizeOfMessages(propertyName, value, open, nav);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfPublicMessages(String propertyName, Object value) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfPublicMessages(propertyName, value);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfSharedFiles(Integer g, Integer flag) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfSharedFiles(g, flag);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfSharedFiles(String userName, Integer flag) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfSharedFiles(userName, flag);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeOfSharedFiles(String userName, Integer g, Integer flag) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.findSizeOfSharedFiles(userName, g, flag);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findTemplates(String propertyName, Object value, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findTemplates(propertyName, value, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List findTopByDaysAndGid(Integer days, Integer g, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.findTopByDaysAndGid(days, g, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}
	}

	@SuppressWarnings("rawtypes")
	public List searchByPropertyAndGid(String propertyName, String value,
			Integer g, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.searchByPropertyAndGid(propertyName, value, g,
					begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List searchByPropertyAndTid(String propertyName, String value,
			Integer g, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.searchByPropertyAndTid(propertyName, value, g,
					begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List searchByPropertyAndUserName(String propertyName, String value,
			String userName, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.searchByPropertyAndUserName(propertyName, value,
					userName, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	@SuppressWarnings("rawtypes")
	public List searchFavouriteMessages(String userName, String propertyName,
			Object value, int begin, int length) {

		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			List result = dao.searchFavouriteMessages(userName, propertyName,
					value, begin, length);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long searchSizeByPropertyAndGid(String propertyName, String value,
			Integer g) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao
					.searchSizeByPropertyAndGid(propertyName, value, g);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long searchSizeByPropertyAndTid(String propertyName, String value,
			Integer g) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao
					.searchSizeByPropertyAndTid(propertyName, value, g);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long searchSizeByPropertyAndUserName(String propertyName,
			String value, String userName) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.searchSizeByPropertyAndUserName(propertyName,
					value, userName);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long searchSizeOfFavouriteMessages(String userName,
			String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			MessageDAO dao = new MessageDAO();
			long result = dao.searchSizeOfFavouriteMessages(userName,
					propertyName, value);
			return result;
		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}